package cn.com.coding.system.dao;

import cn.com.coding.system.domin.dto.UserCardProductDto;
import cn.com.coding.system.domin.UserCardProductEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author mxz
 */
@Mapper
public interface UserCardProductDao extends BaseMapper<UserCardProductEntity> {

    /**
     * card 0 购物车 1 订单 先这么设计
     *
     * @param userPid
     * @return
     */
    List<UserCardProductDto> getCardProductByUserPid(@Param("userPid") String userPid);

    /**
     * 返回购车中的商品集合
     *
     * @param cardPid
     * @return
     */
    @Select("SELECT ucg.pid, ucg.card_pid, ucg.product_pid, ucg.quanity, ucg.price, ucg.product_check, ucg.create_time, ucg.update_time FROM user_card_product ucg WHERE ucg.card_pid = #{cardPid}")
    List<UserCardProductEntity> getCardProductByCardPid(@Param("cardPid") String cardPid);

    @Select("SELECT\n" +
            "ucg.pid,\n" +
            "uc.pid  as card_pid,\n" +
            "uc.update_time,\n" +
            "gi.pid as product_pid,\n" +
            "gi.product_name,\n" +
            "ucg.quanity,\n" +
            "gi.price,\n" +
            "uc.user_pid \n" +
            "FROM\n" +
            "user_card_product ucg\n" +
            "LEFT JOIN user_card uc ON ucg.card_pid = uc.pid \n" +
            "LEFT JOIN product_info gi ON ucg.product_pid = gi.pid \n" +
            "WHERE\n" +
            "ucg.product_check = 1\n" +
            "AND ucg.card_pid = #{cardPid}")
    List<UserCardProductDto> getOrderList(@Param("cardPid") String cardPid);
}
